package com.bolt.support.spring.jpa.jpql;

import com.bolt.support.query.conditions.domain.SqlClause;

public class ParamClause<T> implements SqlClause<String> {

    private final String paramName;

    private final T val;

    private static final String COMMA = ":";


    public static NULL Null = new ParamClause.NULL();

    public ParamClause(String paramName, T val) {
        this.paramName = paramName;
        this.val = val;
    }

    @Override
    public String render(boolean addAlias) {
        return COMMA + paramName;
    }

    public String getParamName() {
        return paramName;
    }

    public Object getVal() {
        return val;
    }


    private static class NULL implements SqlClause<String> {
        private static final String NULL_VALUE = "null";

        @Override
        public String render(boolean addAlias) {
            return NULL_VALUE;
        }
    }
}

 